/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Buku;

import Entity.DatabaseConnection;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Elisa
 */
public class ControllerBukuBaru {

    public static String IDBuku() {
        String IDBuku = "";
        try {
            String sql = "select IDBUKU from BUKU order by IDBUKU desc";
            Connection conn = DatabaseConnection.getConnection();
            PreparedStatement ps = conn.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                IDBuku = (Integer.parseInt(rs.getString(1).substring(2)) + 1) + "";
                while (IDBuku.length() < 4) {
                    IDBuku = "0" + IDBuku;
                }
                IDBuku = "b-" + IDBuku;
            } else {
                IDBuku = "b-0001";
            }

        } catch (SQLException ex) {
            Logger.getLogger(ControllerBukuBaru.class.getName()).log(Level.SEVERE, null, ex);
        }
        return IDBuku;
    }
}
